import { http } from "@/utils/http";
// 转换字符串，undefined,null等转化为""
export function parseStrEmpty(str) {
  if (!str || str == "undefined" || str == "null") {
    return "";
  }
  return str;
}
// 查询用户列表
export function listUser(query?: object) {
  return http.request("get", "/system/user/list", { params: query });
}

// 查询用户详细
export function getUser(userId) {
  return http.request("get", "/system/user/" + parseStrEmpty(userId));
}

// 新增用户
export function addUser(data) {
  return http.request("post", "/system/user", { data });
}

// 修改用户
export function updateUser(data) {
  return http.request("put", "/system/user", { data });
}

// 删除用户
export function delUser(userId) {
  return http.request("delete", "/system/user/" + userId);
}

// 用户密码重置
export function resetUserPwd(userId, password) {
  const data = {
    userId,
    password
  };
  return http.request("put", "/system/user/resetPwd", { data });
}

// 用户状态修改
export function changeUserStatus(userId, status) {
  const data = {
    userId,
    status
  };
  return http.request("put", "/system/user/changeStatus", { data });
}

// 查询用户个人信息
export function getUserProfile() {
  return http.request("get", "/system/user/profile");
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  };
  return http.request("put", "/system/user/profile/updatePwd", { data });
}

// 查询授权角色
export function getAuthRole(userId) {
  return http.request("get", "/system/user/authRole/" + userId);
}

// 保存授权角色
export function updateAuthRole(data) {
  return http.request("put", "/system/user/authRole", { data });
}
